export default class LaunchVueImSocketListener {
    static staticEvents = [
        'connect',
        'error',
        'disconnect',
        'reconnect',
        'reconnect_attempt',
        'reconnecting',
        'reconnect_error',
        'reconnect_failed',
        'connect_error',
        'connect_timeout',
        'connecting',
        'ping',
        'pong',
        'imMessage',
        'imReconnect',
        'imWebMsg',
        'imConnectedError',

        // 音视频
        'subscribed',
        "user-published",
        'microphone-changed',
        'camera-changed',
        'im-rtc-user-published'
    ]

    constructor(io, emitter) {
        this.io = io
        this.register()
        this.emitter = emitter
    }

    register() {
        this.io.onevent = (packet) => {
            let [event, ...args] = packet.data
            if (args.length == 1) {
                args = args[0]
            }
            this.onEvent(event, args)
        }
        LaunchVueImSocketListener.staticEvents.forEach(event => {
            this.io.on(event, (data) => {
                this.onEvent(event, data)
            })
        })
    }

    onEvent(event, args) {
        this.emitter.emit(event, args)
    }
}